

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ab.util.AbViewUtil;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.GBaseActivity;
import com.example.administrator.caigou51.activity.LoginActivity;
import com.example.administrator.caigou51.activity.MessageActivity;
import com.example.administrator.caigou51.activity.SearchActivity;
import com.example.administrator.caigou51.activity.SearchGoodsActivity;
import com.example.administrator.caigou51.control.ImageCycleView;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.card.MainPart1Card;
import com.example.administrator.caigou51.util.ImageUtil;
import com.example.administrator.caigou51.widget.zxing.CaptureActivity;

import java.util.ArrayList;


public class MainPart1CardView extends CardItemView<MainPart1Card> {
 	private Context mContext;
    private LinearLayout linearlayout_banner_container;
    boolean isAdd=false;
    private ImageCycleView mAdView;
    private ImageCycleView.ImageCycleViewListener mAdCycleViewListener;

    public MainPart1CardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public MainPart1CardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public MainPart1CardView(Context context,
                                    AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    @Override
    public void build(final MainPart1Card card) {
        // TODO Auto-generated method stub
        super.build(card);





        linearlayout_banner_container = (LinearLayout) findViewById(R.id.linearlayout_banner_container);


        if (!isAdd) {
            isAdd = true;
            mAdView = new ImageCycleView(mContext, 1, true);
            //设置广告栏长宽，与图片比例一致
            mAdView.setLayoutParams(new ViewGroup.LayoutParams(App.getInstance().screenWidth, App.getInstance().screenWidth * 300 / 750));
            mAdView.setTag(AbViewUtil.NotScale);
            linearlayout_banner_container.addView(mAdView);
            //广告栏监听事件
            mAdCycleViewListener = new ImageCycleView.ImageCycleViewListener() {
                //点击监听
                @Override
                public void onImageClick(String info, int position, View imageView) {
                 /*   if (!TextUtils.isEmpty(info.getLink())) {
                        if (info.getLink().contains("http")) {
                            Intent intent = new Intent(context, WebActivityDiyUrl.class);
                            intent.putExtra(WebActivityDiyUrl.WebUrl, info.getLink());
                            intent.putExtra("title", info.getTitle());
                            context.startActivity(intent);
                        }else{
                            Intent intent = new Intent(context, ActivityActivity.class);
                            intent.putExtra("activity_id", info.getLink());
                            intent.putExtra("activity_name", info.getTitle());
                            context.startActivity(intent);
                        }
                    }*/
                }


                //加载数据
                @Override
                public void displayImage(String imageURL, ImageView imageView) {

                    App.displayImageHttpOrFile(imageURL,imageView, ImageUtil.OptionsActivity());
                  /*  int aa = (int) Math.round(Math.random() * 10);
                    if (aa%2==0)
                        imageView.setImageResource(R.drawable.test_banner_1);
                    else
                        imageView.setImageResource(R.drawable.test_banner_2);*/
                    // App.displayImageHttpOrFile(imageURL, imageView);
                }
            };
        }
      //  if (infos != null) {
            //设置广告栏内容

        mAdView.setImageResources(card.getMainDataBean().getBanner(), mAdCycleViewListener);
      //  }
    }
}
